{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#这个lgb放分类特征\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "#import seaborn as sbn\n",
    "import pandas as pd\n",
    "import lightgbm as lgb\n",
    "import datetime \n",
    "import math \n",
    "import gc\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#输入文件\n",
    "DATA_PATH = os.path.join(os.getcwd(),'data','simply_id','input')\n",
    "NEW_TRAIN  =  os.path.join(DATA_PATH,'new_train.csv')\n",
    "NEW_TEST = os.path.join(DATA_PATH,'new_test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = pd.read_csv(NEW_TRAIN)\n",
    "test = pd.read_csv(NEW_TEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['msno', 'song_id', 'op_type', 'city', 'registered_via',\n",
      "       'registration_init_time', 'song_length', 'song_year', 'first_genre_id',\n",
      "       'artist_name_id', 'lyricist_id', 'language_id',\n",
      "       'lyricist_id_song_cnt_1', 'artist_name_id_song_cnt_1',\n",
      "       'language_id_song_cnt_1', 'first_genre_id_song_cnt_1',\n",
      "       'song_length_song_cnt_1', 'song_year_song_cnt_1', 'target',\n",
      "       'song_id_re_rate', 'song_length_re_rate', 'song_year_re_rate',\n",
      "       'first_genre_id_re_rate', 'artist_name_id_re_rate',\n",
      "       'lyricist_id_re_rate', 'language_id_re_rate', 'song_id_cnt_1',\n",
      "       'song_length_cnt_1', 'song_year_cnt_1', 'first_genre_id_cnt_1',\n",
      "       'artist_name_id_cnt_1', 'lyricist_id_cnt_1', 'language_id_cnt_1',\n",
      "       'msno_cnt_1', 'msno_re_rate', 'city_cnt_1', 'city_re_rate',\n",
      "       'registered_via_cnt_1', 'registered_via_re_rate',\n",
      "       'registration_init_time_cnt_1', 'registration_init_time_re_rate',\n",
      "       'op_type_cnt_1', 'op_type_re_rate'],\n",
      "      dtype='object')\n",
      "Index(['song_id', 'msno', 'op_type', 'target', 'song_length', 'song_year',\n",
      "       'first_genre_id', 'artist_name_id', 'lyricist_id', 'language_id',\n",
      "       'lyricist_id_song_cnt_1', 'artist_name_id_song_cnt_1',\n",
      "       'language_id_song_cnt_1', 'first_genre_id_song_cnt_1',\n",
      "       'song_length_song_cnt_1', 'song_year_song_cnt_1', 'song_id_re_rate',\n",
      "       'song_length_re_rate', 'song_year_re_rate', 'first_genre_id_re_rate',\n",
      "       'artist_name_id_re_rate', 'lyricist_id_re_rate', 'language_id_re_rate',\n",
      "       'song_id_cnt_1', 'song_length_cnt_1', 'song_year_cnt_1',\n",
      "       'first_genre_id_cnt_1', 'artist_name_id_cnt_1', 'lyricist_id_cnt_1',\n",
      "       'language_id_cnt_1', 'city', 'registered_via', 'registration_init_time',\n",
      "       'msno_cnt_1', 'msno_re_rate', 'city_cnt_1', 'city_re_rate',\n",
      "       'registered_via_cnt_1', 'registered_via_re_rate',\n",
      "       'registration_init_time_cnt_1', 'registration_init_time_re_rate',\n",
      "       'op_type_cnt_1', 'op_type_re_rate'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(train.columns)\n",
    "print(test.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = train[['msno', 'song_id', 'op_type', 'city', 'registered_via',\n",
    "       'registration_init_time', 'song_length', 'song_year', 'first_genre_id',\n",
    "       'artist_name_id', 'lyricist_id', 'language_id','target']]\n",
    "test = test[['msno', 'song_id', 'op_type', 'city', 'registered_via',\n",
    "       'registration_init_time', 'song_length', 'song_year', 'first_genre_id',\n",
    "       'artist_name_id', 'lyricist_id', 'language_id','target']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for col in train.columns:\n",
    "    if train[col].dtype == object:\n",
    "        train[col] = train[col].astype('category')\n",
    "for col in test.columns:\n",
    "    if test[col].dtype == object:\n",
    "        test[col] = test[col].astype('category')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X_train = train.drop(['target'], axis=1).values\n",
    "y_train = train['target'].values\n",
    "X_test = test.drop(['target'], axis=1).values\n",
    "y_test = test['target'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "d_train_final = lgb.Dataset(X_train, y_train)\n",
    "watchlist_final = lgb.Dataset(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "params = {\n",
    "        'objective': 'binary',\n",
    "        'metric': 'binary_logloss',\n",
    "        'boosting': 'gbdt',\n",
    "        'learning_rate': 0.1,\n",
    "        'verbose': 0,\n",
    "        'num_leaves': 108,\n",
    "        'bagging_fraction': 0.9,\n",
    "        'bagging_freq': 2,\n",
    "        'bagging_seed': 3,\n",
    "        'feature_fraction': 0.8,\n",
    "        'feature_fraction_seed': 2,\n",
    "        'max_bin': 256,\n",
    "        'max_depth': 12,\n",
    "        'num_rounds': 500,\n",
    "        'metric' : 'auc',\n",
    "        'using_missing' : False,\n",
    "        'is_unbalance' : True\n",
    "        #'sigmoid' : 1.0 ,\n",
    "        #'train_metric' : True\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Users\\10100\\Anaconda3\\lib\\site-packages\\lightgbm\\engine.py:99: UserWarning: Found `num_rounds` in params. Will use it instead of argument\n",
      "  warnings.warn(\"Found `{}` in params. Will use it instead of argument\".format(alias))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5]\tvalid_0's auc: 0.671558\n",
      "[10]\tvalid_0's auc: 0.673754\n",
      "[15]\tvalid_0's auc: 0.677135\n",
      "[20]\tvalid_0's auc: 0.679195\n",
      "[25]\tvalid_0's auc: 0.681254\n",
      "[30]\tvalid_0's auc: 0.683687\n",
      "[35]\tvalid_0's auc: 0.685079\n",
      "[40]\tvalid_0's auc: 0.687176\n",
      "[45]\tvalid_0's auc: 0.688891\n",
      "[50]\tvalid_0's auc: 0.690753\n",
      "[55]\tvalid_0's auc: 0.691887\n",
      "[60]\tvalid_0's auc: 0.6934\n",
      "[65]\tvalid_0's auc: 0.694531\n",
      "[70]\tvalid_0's auc: 0.695921\n",
      "[75]\tvalid_0's auc: 0.696995\n",
      "[80]\tvalid_0's auc: 0.698305\n",
      "[85]\tvalid_0's auc: 0.699262\n",
      "[90]\tvalid_0's auc: 0.699888\n",
      "[95]\tvalid_0's auc: 0.70099\n",
      "[100]\tvalid_0's auc: 0.701985\n",
      "[105]\tvalid_0's auc: 0.702604\n",
      "[110]\tvalid_0's auc: 0.703439\n",
      "[115]\tvalid_0's auc: 0.70427\n",
      "[120]\tvalid_0's auc: 0.70495\n",
      "[125]\tvalid_0's auc: 0.705763\n",
      "[130]\tvalid_0's auc: 0.706302\n",
      "[135]\tvalid_0's auc: 0.707335\n",
      "[140]\tvalid_0's auc: 0.707992\n",
      "[145]\tvalid_0's auc: 0.708533\n",
      "[150]\tvalid_0's auc: 0.709168\n",
      "[155]\tvalid_0's auc: 0.709566\n",
      "[160]\tvalid_0's auc: 0.710007\n",
      "[165]\tvalid_0's auc: 0.710608\n",
      "[170]\tvalid_0's auc: 0.711049\n",
      "[175]\tvalid_0's auc: 0.711758\n",
      "[180]\tvalid_0's auc: 0.712406\n",
      "[185]\tvalid_0's auc: 0.712898\n",
      "[190]\tvalid_0's auc: 0.713352\n",
      "[195]\tvalid_0's auc: 0.713787\n",
      "[200]\tvalid_0's auc: 0.714363\n",
      "[205]\tvalid_0's auc: 0.714822\n",
      "[210]\tvalid_0's auc: 0.715528\n",
      "[215]\tvalid_0's auc: 0.715951\n",
      "[220]\tvalid_0's auc: 0.7166\n",
      "[225]\tvalid_0's auc: 0.716831\n",
      "[230]\tvalid_0's auc: 0.717263\n",
      "[235]\tvalid_0's auc: 0.717468\n",
      "[240]\tvalid_0's auc: 0.718159\n",
      "[245]\tvalid_0's auc: 0.718476\n",
      "[250]\tvalid_0's auc: 0.718869\n",
      "[255]\tvalid_0's auc: 0.719248\n",
      "[260]\tvalid_0's auc: 0.719775\n",
      "[265]\tvalid_0's auc: 0.720264\n",
      "[270]\tvalid_0's auc: 0.720523\n",
      "[275]\tvalid_0's auc: 0.720729\n",
      "[280]\tvalid_0's auc: 0.721164\n",
      "[285]\tvalid_0's auc: 0.721824\n",
      "[290]\tvalid_0's auc: 0.722461\n",
      "[295]\tvalid_0's auc: 0.72295\n",
      "[300]\tvalid_0's auc: 0.723463\n",
      "[305]\tvalid_0's auc: 0.723817\n",
      "[310]\tvalid_0's auc: 0.724178\n",
      "[315]\tvalid_0's auc: 0.724392\n",
      "[320]\tvalid_0's auc: 0.724719\n",
      "[325]\tvalid_0's auc: 0.725224\n",
      "[330]\tvalid_0's auc: 0.725506\n",
      "[335]\tvalid_0's auc: 0.725633\n",
      "[340]\tvalid_0's auc: 0.725923\n",
      "[345]\tvalid_0's auc: 0.726217\n",
      "[350]\tvalid_0's auc: 0.726317\n",
      "[355]\tvalid_0's auc: 0.726761\n",
      "[360]\tvalid_0's auc: 0.727091\n",
      "[365]\tvalid_0's auc: 0.72728\n",
      "[370]\tvalid_0's auc: 0.727537\n",
      "[375]\tvalid_0's auc: 0.727897\n",
      "[380]\tvalid_0's auc: 0.728064\n",
      "[385]\tvalid_0's auc: 0.728404\n",
      "[390]\tvalid_0's auc: 0.728767\n",
      "[395]\tvalid_0's auc: 0.729042\n",
      "[400]\tvalid_0's auc: 0.72942\n",
      "[405]\tvalid_0's auc: 0.729666\n",
      "[410]\tvalid_0's auc: 0.729805\n",
      "[415]\tvalid_0's auc: 0.730094\n",
      "[420]\tvalid_0's auc: 0.73024\n",
      "[425]\tvalid_0's auc: 0.730366\n",
      "[430]\tvalid_0's auc: 0.730712\n",
      "[435]\tvalid_0's auc: 0.731147\n",
      "[440]\tvalid_0's auc: 0.731237\n",
      "[445]\tvalid_0's auc: 0.731516\n",
      "[450]\tvalid_0's auc: 0.731861\n",
      "[455]\tvalid_0's auc: 0.732147\n",
      "[460]\tvalid_0's auc: 0.732337\n",
      "[465]\tvalid_0's auc: 0.73279\n",
      "[470]\tvalid_0's auc: 0.733097\n",
      "[475]\tvalid_0's auc: 0.733359\n",
      "[480]\tvalid_0's auc: 0.733563\n",
      "[485]\tvalid_0's auc: 0.733927\n",
      "[490]\tvalid_0's auc: 0.734279\n",
      "[495]\tvalid_0's auc: 0.734428\n",
      "[500]\tvalid_0's auc: 0.734782\n",
      "Wall time: 7min 13s\n"
     ]
    }
   ],
   "source": [
    "%time model_f1 = lgb.train(params, train_set=d_train_final,  valid_sets=watchlist_final,verbose_eval=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1449342  823987]\n",
      " [ 757305 1837217]]\n",
      "[[359450 208560]\n",
      " [192317 456636]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "from scipy import interp \n",
    "cm_train = metrics.confusion_matrix(y_train,model_f1.predict(X_train).round())  #训练样本的混淆矩阵\n",
    "print(cm_train)\n",
    "cm_test = metrics.confusion_matrix(y_test,model_f1.predict(X_test).round())  #训练样本的混淆矩阵\n",
    "print(cm_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  1.,  1.,  0.,  1.])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_test_1 = model_f1.predict(X_test).round()\n",
    "p_test_1[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHpdJREFUeJzt3Xl4lOW9//H3l7BDCEuSkT0sARIQ\nWYIg0CqHUNFatFY9oNLa4yWyaY/2Z9W2x1o93azW2h5aS/vzWEFEqi3QFmsJhWqtKAkgQgIY9ggm\nYQtr1rl/f0zqL8ZgRpiZZ5bP67q4rnlmHjKfJxM+ebjve+Yx5xwiIhJfWngdQEREQk/lLiISh1Tu\nIiJxSOUuIhKHVO4iInFI5S4iEodU7iIicUjlLiISh1TuIiJxqKVXT5yamuoyMjK8enoRkZhUUFBw\n2DmX1tx+npV7RkYG+fn5Xj29iEhMMrN9weynYRkRkTikchcRiUMqdxGROKRyFxGJQyp3EZE41Gy5\nm9kzZlZmZlvP8biZ2c/MrNjMtpjZqNDHFBGRTyOYM/dngamf8PhVQGb9n1nALy88loiIXIhmy905\n9xpw9BN2uRZ4zgWsBzqbWfdQBRQRiRd1fseGvUepqfOH/blC8SamnsCBBtsl9fcdaryjmc0icHZP\nnz59QvDUIiLR7XRVLa+/V87qwjLW7ijD16ktC2eOpnfX9mF93lCUuzVxX5NX3XbOLQQWAuTk5OjK\n3CISlw5VnCWvqIw1RaXk7z3GyD6dyc3ycc+UTHp1CW+p/0soyr0E6N1guxdwMARfV0QkJjjn2Hbw\nBHlFpeQVlVJy7CyTBqdzw+he/GzGSDq1bRXxTKEo95XAfD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krgy/WrZsYBFc65QyH76l7P\nKDcz23w1sJPALPu36u97hMA/bgi8+L8DioG3gf5eZ47AMecBpcDm+j8rvc4c7mNutO86Yny1TJCv\nswE/AQqBd4HpXmeOwDFnA28QWEmzGfic15kv8HhfAA4BNQTO0m8HZgOzG7zGC+q/H++G+uda71AV\nEYlD0TwsIyIi50nlLiISh1TuIiJxSOUuIhKHVO4iInFI5S4iEodU7iIicUjlLiISh/4fEG0xdnLS\nAykAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x13eabc5fbe0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#roc曲线\n",
    "fpr, tpr, thresholds = metrics.roc_curve(y_test, p_test_1,pos_label = 1)##指定正例标签，pos_label = ###########在数之联的时候学到的，要制定正例 \n",
    "mean_fpr = np.linspace(0, 1, 100) \n",
    "mean_tpr = 0.0 #初始处为0 \n",
    "mean_tpr += interp(mean_fpr, fpr, tpr)          #对mean_tpr在mean_fpr处进行插值，通过scipy包调用interp()函数    \n",
    "                                 \n",
    "roc_auc = metrics.auc(fpr, tpr)    \n",
    "#画图，只需要plt.plot(fpr,tpr),变量roc_auc只是记录auc的值，通过auc()函数能计算出来    \n",
    "plt.plot(fpr, tpr, lw=1, label='ROC  (area = %0.3f)' % roc_auc) \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
